<template>
	<view>
		<view class="swiper" style="padding: 20rpx;background-color: #fff;">
			<u-swiper :list="swiperList" @click="to" height="300"></u-swiper>
		</view>
		<!-- <view class="cate">
			<view class="title1" style="color: white;writing-mode: vertical-lr;">活动分类</view>
			<view class="cate-list">
				<u-button class="cate-item" v-for="item in cateList" type="warning" plain>{{item.name}}</u-button>
			</view>
		</view> -->
		<view class="news" style="margin-top: 20rpx;">
			<u-sticky offset-top="0">
				<u-tabs :list="tabList" :is-scroll="true" :current="tabCurrent" @change="tabChange"></u-tabs>
			</u-sticky>
			<view class="news-list" style="display: flex;flex-direction: column;padding: 20rpx;background-color: #fff;">
				<view class="news-item" style="padding: 20rpx 0;border-top: 2rpx solid #e4e7ed;display: flex;flex-direction: row;
				justify-content: space-between;" v-for="item in activityList">
					<view class="left" style="width: 450rpx;">
						<view class="top" style="height: 168rpx;">
							<text style="font-size: 32rpx;font-weight: bold;" class="line">{{item.name}}</text>
						</view>
						<view class="bottom" style="display: flex;flex-direction: row;color: #666;font-size: 22rpx;">
							<text>{{item.signupNum}} 人报名</text>
							<text style="margin-left: 20rpx;">{{item.likeNum}} 点赞</text>
						</view>
					</view>
					<view class="right center">
						<navigator :url="`/pages/activity-detail/activity-detail?id=${item.id}`">
							<image :src="$baseUrl + item.imgUrl" mode="" style="width: 250rpx;height: 200rpx;"></image>
						</navigator>
					</view>
				</view>
				<u-divider color="#909399">没有更多了</u-divider>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				swiperList: [],
				tabList: [],
				tabCurrent: 0,
				activityList: []
			};
		},
		onLoad() {
			this.getSwiper()
			this.getTab()
		},
		methods:{
			getSwiper(){
				this.$request({
					url: '/prod-api/api/activity/rotation/list',
				}).then(res => {
					console.log(res)
					this.swiperList = res.rows.map(item => ({image: this.$baseUrl + item.advImg, id: item.id}))
				})
			},
			to(index){
				uni.navigateTo({
					url:'/pages/activity-detail/activity-detail?id=' + this.swiperList[index].id
				})
			},
			getTab(){
				this.$request({
					url: '/prod-api/api/activity/category/list'
				}).then(res => {
					this.tabList = res.data
					this.getActivity()
				})
			},
			getActivity(){
				this.$request({
					url: '/prod-api/api/activity/activity/list',
					data: {
						categoryId: this.tabList[this.tabCurrent].id
					}
				}).then(res => {
					console.log(res)
					this.activityList = res.rows
				})
			},
			tabChange(index){
				this.tabCurrent = index
				this.getActivity()
			}
		}
	}
</script>

<style lang="scss">
page{
	background-color: #f7f7f7;
	view{
		// .cate{
		// 	margin-top: 20rpx;
		// 	background-color: #fab6b6;
		// 	padding: 20rpx;
		// 	display: flex;
		// 	flex-direction: row;
		// 	justify-content: space-between;
		// 	.cate-list{
		// 		display: flex;
		// 		flex-direction: row;
		// 		flex-wrap: wrap;
		// 		.cate-item{
		// 			margin-left: 10rpx;
		// 			flex: 1;
		// 			margin-top: 20rpx;
		// 		}
		// 	}
		// }
	}
}
</style>
